<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\DB;


class Role extends Model
{
    use  Notifiable;
    public $timestamps = false;
    protected $table = 'roles';
    protected $fillable = [
        'name','slug','description'
    ];
    protected $appends = ['permission'];
    public function getPermissionAttribute()
    {
        $p = DB::table('role_permission')
            ->join('permissions', 'role_permission.permission_id', '=', 'permissions.id')
            ->where(['role_permission.role_id'=>$this->attributes['id']])->pluck('permissions.id')->toArray();
        $result=[];
        if($p){
            foreach ($p as $items){
                $result[]=(string)$items;
            }
        }
        return $result;
    }
//    protected $validationMessages = [
//        'keywords.unique' => '该关键字已经被注册过了',
//    ];
}
